/**
 * 发送自定义事件
 * @param {*} webview
 * @param {*} eventType
 * @param {*} data
 */
export const fire = function (webview, eventType, data) {
  console.log(data);
  webview &&
    webview.evalJS(`
  document.dispatchEvent(new CustomEvent("${eventType}", {
    detail:${JSON.stringify(data)},
    bubbles: true,
    cancelable: true
  }));
  `);
};

// 获取设备id
export function getDeviceId() {
  // let deviceId = plus.device.uuid;
  // return deviceId

  var mainActivity = plus.android.runtimeMainActivity()
  var Settings = plus.android.importClass('android.provider.Settings')
  let deviceId = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure.ANDROID_ID)
  return deviceId
}

//秒转换成时分秒
export function formatSeconds(value) {
  var theTime = parseInt(value); // 秒
  var theTime1 = 0; // 分
  var theTime2 = 0; // 小时
  // alert(theTime);
  if (theTime > 60) {
    theTime1 = parseInt(theTime / 60);
    theTime = parseInt(theTime % 60);
    // alert(theTime1+"-"+theTime);
    if (theTime1 > 60) {
      theTime2 = parseInt(theTime1 / 60);
      theTime1 = parseInt(theTime1 % 60);
    }
  }
  var result = "" + parseInt(theTime) + "秒";
  if (theTime1 > 0) {
    result = "" + parseInt(theTime1) + "分" + result;
  }
  if (theTime2 > 0) {
    result = "" + parseInt(theTime2) + "小时" + result;
  }
  return result;
}
